import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '../components/Layout/index'

Vue.use(VueRouter)

/**
 * Note: sub-menu only appear when route children.length >= 1
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

export const constantRoutes = [
	{
		path: '/login',
		name: 'login',
		component: () => import('@/pages/login/Login.vue'),
		meta: {
			title: '登录',
			requireAuth: false, //表示进入此路由不需要验证
		},
		hidden: true,
	},
	// {
	// 	path: '/',
	// 	component: Layout,
	// 	redirect: '/admin',
	// 	children: [
	// 		{
	// 			path: '/admin',
	// 			name:'admin',
	// 			component: () => import('@/pages/number-screen/index.vue'),
	// 			meta: {
	// 				title: '数字大屏',
	// 				src: require('@/assets/icons/sidebar-admin.png'),
	// 			},
				
	// 		},
	// 	],
	// },
	// {
	// 	path: '/realtime-control',
	// 	name: 'realtimecontrol',
	// 	component: Layout,
	// 	meta: {
	// 		title: '实时控制',
	// 		permissions: ['/web/duty'],
	// 	},
	// 	children: [
	// 		{
	// 			path: '/realtimecontrol',
	// 			component: () => import('@/pages/admin'),
	// 			meta: {
	// 				title: '实时控制',
	// 				src: require('@/assets/icons/realtime-control.png'),
	// 			},
	// 		},
	// 	],
	// },
		
	// {
	// 	path: '/largescreen',
	// 	component: Layout,
	// 	redirect: '/largescreen',
	// 	children: [
	// 		{
	// 			path: '/largescreen',
	// 			name:'largescreen',
	// 			component: () => import('@/pages/wenzhou-largescreen/index.vue'),
	// 			meta: {
	// 				title: '数据大屏',
	// 				level:1,
	// 				src: require('@/assets/icons/largescreen-admin.png'),
	// 			},
				
	// 		},
	// 	],
	// },
	{
		path: '/observe',
		component: Layout,
		redirect: '/observe',
		children: [
			{
				path: '/observe',
				name:'observe',
				component: () => import('@/pages/observe'),
				meta: {
					title: '观察视图',
					level:1,
					src: require('@/assets/icons/sidebar-admin.png'),
				},
				
			},
		],
	},
	
	{
		path: '/',
		component: Layout,
		redirect: '/admin',
		children: [
			{
				path: '/admin',
				name:'admin',
				component: () => import('@/pages/admin'),
				meta: {
					title: '实时控制',
					level:1,
					src: require('@/assets/icons/sidebar-admin.png'),
				},
				
			},
		],
	},
	{
		path: '/alarm-data',
		name: 'alarmData',
		component: () => import('@/pages/alarm-data'),
		meta: {
			title: '报警数据',
		},
		hidden: true,
	},
	{
		path: '/realtime-data',
		name: 'realtimeData',
		component: () => import('@/pages/realtime-data'),
		meta: {
			title: '实时状态',
		},
		hidden: true,
	},
	{
		path: '/weekly-electricity-report',
		name: 'weeklyElectricityReport',
		component: () => import('@/pages/weekly-electricity-report'),
		meta: {
			title: '用电量周报',
		},
		hidden: true,
	},

]

export const asyncRoutes = [
	{
		path: '/user',
		
		component: Layout,
		meta: {
			title:'公司用户',
			permissions: ['/user/company'],
			src: require('@/assets/icons/sidebar-user-group.png'),
		},
		children: [
			{
				path: '/user',
				name: 'user',
				component: () => import('@/pages/user-manage'),
				meta: {
					title: '用户管理',
					permissions: ['/user/user'],
					src: require('@/assets/icons/sidebar-user.png'),
				},
			},
			{
				path: '/user-group',
				name: 'userGroup',
				component: () => import('@/pages/user-group'),
				meta: {
					title: '用户分组',
					permissions: ['/user/usergroup'],
					src: require('@/assets/icons/sidebar-user-group.png'),
				},
			},
			{
				path: '/crossuser',
				name: 'crossuser',
				component: () => import('@/pages/cross-user'),
				meta: {
					title: '跨区用户',
					permissions: ['/user/crossuser'],
					src: require('@/assets/icons/cross-user.png'),
				},
			},
		],
	},
	// {
	// 	path: '/duty',
	// 	name: 'duty',
	// 	component: Layout,
	// 	meta: {
	// 		title: '权限管理',
	// 		permissions: ['/web/duty'],
	// 	},
	// 	children: [
	// 		{
	// 			path: '/duty',
	// 			component: () => import('@/pages/authority'),
	// 			meta: {
	// 				title: '权限管理',
	// 				src: require('@/assets/icons/sidebar-auth.png'),
	// 			},
	// 		},
	// 	],
	// },
	// {
	// 	path: '/user-group',
	
	// 	component: Layout,
	// 	meta: {
	// 		title: '用户分组',
	// 		permissions: ['/web/duty'],
	// 	},
	// 	children: [
			
	// 	],
	// },
	{
		path: '/control-group',
		name: 'controlGroup',
		component: Layout,
		meta: {
			title: '群控管理',
			permissions: ['/user/controlmanage'],
			src: require('@/assets/icons/sidebar-control-group.png'),
		},
		children: [
			{
				path: '/controlpanel-group',
				name: 'controlpanelGroup',
				component: () => import('@/pages/controlpanel-group'),
				meta: {
					title: '中控屏分组',
					permissions: ['/user/controlgroup'],
					src: require('@/assets/icons/sidebar-control-group.png'),
				},
			},
			{
				path: '/control-group',
				name: 'controlGroup',
				component: () => import('@/pages/control-group'),
				meta: {
					title: '控制分组',
					permissions: ['/user/controlgroup'],
					src: require('@/assets/icons/sidebar-control-group.png'),
				},
			},
			{
				path: '/control-strategy',
				name: 'controlStrategy',
				component: () => import('@/pages/control-strategy'),
				meta: {
					title: '控制策略',
					permissions: ['/user/controlstrategy'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
			{
				name: 'userinstructions',
				path: '/user-instructions',
				component: () => import('@/pages/user-instructions'),
				meta: {
					title: '指令管理',
					permissions: ['/user/userinstructions'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
		
			{
				name: 'probereportdata',
				path: '/probe-reportdata',
				component: () => import('@/pages/probe-reportdata'),
				meta: {
					title: '上报日志',
					permissions: ['/user/probereportdata'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
			
		],
	},
	{
		path: '/scene-linkage',
		name: 'scenelinkage',
		component: Layout,
		meta: {
			title: '场景联动管理',
			permissions: ['/user/controlmanage'],
			src: require('@/assets/icons/sidebar-control-group.png'),
		},
		children: [
			
			{
				name: 'scenegrouping',
				path: '/scene-grouping',
				component: () => import('@/pages/scene-grouping/index.vue'),
				meta: {
					title: '场景设备分组',
					permissions: ['/user/userinstructions'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
			
			{
				name: 'scenelinkage',
				path: '/scene-linkage',
				component: () => import('@/pages/scene-linkage/index.vue'),
				meta: {
					title: '场景联动配置',
					permissions: ['/user/userinstructions'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
		],
	},
	{
		path: '/organreport',
		name: 'organreport',
		component: Layout,
		meta: {
			title: '网点配置',
			permissions: ['/user/organreport'],
		},
		children: [
			{
				path: '/organreport',
				component: () => import('@/pages/organ-report'),
				meta: {
					title: '网点配置',
					level:1,
					permissions: ['/user/organreport'],
					src: require('@/assets/icons/cross-user.png'),
				},
			},
		],
	},
	{
		path: '/topo',
		name: 'topo',
		component: Layout,
		meta: {
			title: '拓扑图管理',
			permissions: ['/user/controlmanage'],
			src: require('@/assets/icons/sidebar-control-group.png'),
		},
		children: [
			
			{
				name: 'topo',
				path: '/topo',
				component: () => import('@/pages/pageTuopuList/pageTuopuList.vue'),
				meta: {
					title: '拓扑图列表',
					permissions: ['/user/userinstructions'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
			},
			
			{
				name: 'topoedit',
				path: '/topoedit',
				component: () => import('@/pages/pagetuopo/topo.vue'),
				meta: {
					title: '拓扑图编辑',
					permissions: ['/user/userinstructions'],
					src: require('@/assets/icons/sidebar-strategy.png'),
				},
				hidden: true,
			},
		],
	},
	{
		path: '/topuPreview',
		name: 'tuopuPreview',
		component: () => import('@/pages/pageTuopuPreview/pageTuopuPreview.vue'),
		meta: {
			title: '预览',
		
		},
		hidden: true,
	},
	
]

//
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
	return originalPush.call(this, location).catch((err) => err)
}

const createRouter = () =>
	new VueRouter({
		// mode: 'history',
		mode: 'hash',
		//base: process.env.BASE_URL,
		base: '/shike3k/user/',
		routes: constantRoutes,
	})

const router = createRouter()

export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
